package com.tom.architect02.p4.day37.simple5.base;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

/**
 * Added by Tom on 2024/01/29. <BaseView>
 */
public abstract class BaseMvpActivity<P extends BasePresenter>
        extends AppCompatActivity implements BaseView {
    private P mPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView();

        // 创建P, 交给子类具体去时间。
        mPresenter = createPresenter();
        mPresenter.attach(this); // 绑定
        initView();
        initData();
    }

    // 子类去实现，每个Activity 实现不同。
    protected abstract P createPresenter();

    public P getPresenter() {
        return mPresenter;
    }

    protected abstract void initView();

    protected abstract void initData();

    protected abstract void setContentView();

    @Override
    public void onDestroy() {
        super.onDestroy();
        mPresenter.detach();
    }

}
